import time


class submit:
    from DrissionPage import WebPage, ChromiumOptions
    # 创建 ChromiumOptions 实例，设置远程调试端口
    co = ChromiumOptions(9222)
    # 创建 WebPage 实例，连接到已经打开的浏览器
    page = WebPage(chromium_options=co)
    def submit(self,url):


        #中心  C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222
        #家   C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe --remote-debugging-port=9222
        # page.run_js("document.getElementsByClassName('top-nav-item')[6].click()")
        self.page.get("{}".format(url))

        self.page.wait.ele_displayed("xpath://*[@class='btn btn-info apply-notice-modal-confirm']")

        self.page.run_js("document.getElementsByClassName('btn btn-info apply-notice-modal-confirm')[0].click()")
        self.page.run_js("document.getElementById('linkAddress').value='贵州省遵义市凤冈县'")
        self.page.run_js("document.getElementsByClassName('btn material-btn upload-btn')[0].click()")

        self.page.wait.ele_displayed("xpath://*[@class='layui-layer-btn0']")

        self.page.run_js(
            "var inputs = document.getElementsByClassName('upload-input fileupload');for (var i = 0; i < inputs.length; i++) {inputs[i].type = 'text';}")

        # 关闭文件提示
        ele = self.page.run_js("document.getElementsByClassName('layui-layer-btn0')[0].click()")

        self.page.run_js(
            "var inputs = document.getElementsByClassName('upload-input fileupload');for (var i = 0; i < inputs.length; i++) {inputs[i].type = 'file';}")

        # page.set.upload_files(r"C:\Users\Administrator\Pictures\Screenshots\屏幕截图 2024-06-05 155825.png")
        # #
        # # # time.sleep(5)
        # page('xpath://*[@class="upload-input fileupload" and @resourcename="职业资格证书或职业技能等级证书"]/preceding-sibling::*[1]').click()
        # page.wait.upload_paths_inputted()
        # ele2.click.to_upload(r"C:\Users\Administrator\Pictures\Screenshots\屏幕截图 2024-06-05 155825.png")
        self.page.wait.ele_displayed('xpath://*[@class="upload-input fileupload"')

        ele3 = self.page('xpath://*[@class="upload-input fileupload" and @resourcename="领取待遇人员的银行账户信息"]').prev()
        ele3.click.to_upload(r"D:\A临时交换空间\申请材料(1)\关于冷晓丽技能提升补贴申领的业务\银行卡.docx")

        ele3 = self.page('xpath://*[@class="upload-input fileupload" and @resourcename="职业资格证书或职业技能等级证书"]').prev()
        ele3.click.to_upload(r"D:\A临时交换空间\申请材料(1)\关于冷晓丽技能提升补贴申领的业务\中级消防设施操作员-冷晓丽.jpg")

        ele3 = self.page('xpath://*[@class="upload-input fileupload" and @resourcename="有效身份证件"]').prev()
        ele3.click.to_upload(r"D:\A临时交换空间\申请材料(1)\关于冷晓丽技能提升补贴申领的业务\身份证.docx")

        len=self.page.run_js("var a=document.getElementsByClassName('file-tr').length;return a;")
        if len<2:
            time.sleep(5)

        # 只能核对并提交

        self.page.wait.ele_displayed('xpath://*[@id="IntelligentCheckBtn"]')
        self.page('xpath://*[@id="IntelligentCheckBtn"]').click()



        # 核对材料之后提交
        self.page.wait.ele_displayed('xpath://*[@class="btn btn-primary" and text()="提交" ]')

        #self.page('xpath://*[@class="btn btn-primary" and text()="提交" ]').click()
        try:
            self.page('xpath://*[@class="btn btn-primary" and text()="提交" ]').click()
        except: self.page('xpath://*[@id="IntelligentCheckBtn"]').click();self.page('xpath://*[@class="btn btn-primary" and text()="提交" ]').click();


        # if page.run_js("document.getElementsByClassName('layui-layer layui-layer-page')"):
        #     page.run_js("document.getElementsByClassName('layui-layer layui-layer-page')[0].remove()")
        #检测二次申报
        if self.page.wait.ele_displayed("xpath://*[@class='layui-layer-btn0']"):
            self.page("xpath://*[@class='layui-layer-btn0']").click()



        #
        # ele3=page('xpath://*[@class="upload-input fileupload" and @resourcename="有效身份证件"]').prev()
        # ele3.click.to_upload(r"C:\Users\Administrator\Pictures\Screenshots\屏幕截图 2024-06-05 155825.png")
        # #ele2.click()
        # # page.wait.upload_paths_inputted()
        #
        # # ele.click.to_upload(r"C:\Users\Administrator\Pictures\Screenshots\屏幕截图 2024-06-05 155825.png")
